package q1768_mergeAlternately;

public class Solution {
    /*
    交替合并字符串
    直接双指针可解
     */
    public String mergeAlternately(String word1, String word2) {
        int p1 = 0, p2 = 0, n1 = word1.length(), n2 = word2.length();
        StringBuilder sb = new StringBuilder();
        while (p1 < n1 || p2 < n2) {
            if (p1 < n1) sb.append(word1.charAt(p1));
            if (p2 < n2) sb.append(word2.charAt(p2));
            ++p1;
            ++p2;
        }
        return sb.toString();
    }
}
